home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 4 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.5 KB  |  124 lines

  1. Path: in2.uu.net!bounce-back
  2. Date: 03 Jan 96 15:59:21 GMT
  3. Approved: fjh@cs.mu.oz.au
  4. From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
  5. Newsgroups: comp.std.c++
  6. Subject: Re: Nested template class definitions
  7. X-Original-Date: Wed, 03 Jan 1996 13:32:55 GMT
  8. Organization: CCN Market Analysis
  9. Message-ID: <864730614wnr@ma.ccngroup.com>
  10. References: <9600116.2625@mulga.cs.mu.OZ.AU> <4c525e$one@nnrp1.news.primenet.com>
  11. Reply-To: aGriffiths@ma.ccngroup.com
  12. X-Broken-Date: Wednesday, Jan 03, 1996 13.32.55 GMT
  13. X-Newsreader: Newswin Alpha 0.6
  14. X-Mail2News-Path: devmaccn.demon.co.uk
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBFAgUBMOqn5+EDnX0m9pzZAQHzgAGAheYGrt9llWeAnHsINMgCjY8BeIbZYyBD
  17.     paqAPli+si5Pdf5AEn+PIqJHuHGuqyqi
  18.     =jcUw
  19.  
  20. I fear we're getting off topic, but there are a lot of programmers 
  21. that will be thinking that the language implemented by Microsoft bears
  22. some relationship to the standard.
  23.  
  24. In fact MSVC4 has quite a few problems with nested classes 
  25. and templates (examples below).  (I don't think MS incorporated 
  26. anything more recent than mid '94 - certainly not the public review 
  27. draft ANSI produced.)
  28.  
  29. The public draft is also far from clear in some areas (e.g. tempates
  30. and the interaction between namespace and templates).  In particular
  31. I feel that the second example below should be valid (without the
  32. MSVC fix), but finding clear statements justifying this is beyond me.
  33.  
  34.  
  35. Example 1:
  36.  
  37.     #include <vector.h>
  38.  
  39.     #if defined(_MSC_VER) && (_MSC_VER <= 1000)
  40.         template<class T> class Class_Value {
  41.             public:
  42.                 Class_Value() {}
  43.                 Class_Value(const T& t) : v(t) {}
  44.  
  45.             private:
  46.                 T v;
  47.          };
  48.     #endif
  49.  
  50.     template<class T> class Class {
  51.         public:
  52.  
  53.         #if !(defined(_MSC_VER) && (_MSC_VER <= 1000))
  54.             class Value {
  55.                 public:
  56.                     Value() {}
  57.                     Value(const T& t) : v(t) {}
  58.  
  59.                 private:
  60.                     T v;
  61.             };
  62.         #else
  63.             typedef ::Class_Value<T> Value;
  64.         #endif
  65.  
  66.             Value f(const T& t) const { return t; }
  67.  
  68.         private:
  69.  
  70.             // MS resolves this with incorrect name binding
  71.             // - see above conditionals
  72.             vector<Value> array;
  73.     };
  74.  
  75.     typedef  Class<int> IntClass;
  76.  
  77.     int main() {
  78.         IntClass c;
  79.         IntClass::Value v = c.f(0);
  80.         return 0;
  81.     }
  82.  
  83. Example 2:
  84.  
  85.     #include <vector.h>
  86.  
  87.     namespace MyNameSpace {
  88.         template<class T> class Element {
  89.             public: T t;
  90.         };
  91.  
  92.         template<class T> class Container {
  93.             public: vector<MyNameSpace::Element<T> > array;
  94.         };
  95.     }
  96.                     
  97.     #if defined(_MSC_VER) && (_MSC_VER <= 1000)
  98.         using MyNameSpace::Element<int>;
  99.     #endif
  100.  
  101.     typedef MyNameSpace::Element<int>   MyIntElement;
  102.     typedef MyNameSpace::Container<int> MyIntContainer;
  103.  
  104.     int main() {
  105.         MyIntContainer collection;
  106.         MyIntElement   e;
  107.         e.t = 1;
  108.  
  109.         collection.array.push_back(e);
  110.  
  111.         return 0;
  112.     }
  113.  
  114. --
  115. Alan Griffiths               | Also editor of: The ISDF Newsletter
  116. Senior Systems Consultant,   | (An Association of C and C++ Users publication)
  117. CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
  118. (agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)
  119.  
  120. ---
  121. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  122.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  123.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  124.